<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>扫码</title>
		<link rel="stylesheet" href="../css/common.css" />
		<style>
			.mask {
				height: 100%;
				width: 100%;
				position: absolute;
				top: 0;
				background: #ffffff;
			}
		</style>
	</head>

	<body>
		<div class="mask" id="mask">

		</div>
		<script src="../config.js"></script>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript">
			mui.init()
			var scan;
			var userInfo = {}
			var currentShopObj
			var extra
			var type
			if(window.plus) {
				plusready();
			} else {
				document.addEventListener('plusready', plusready, false);
			}

			function plusready() {
				receiveParams()
				setTimeout(function() {
					scan = new plus.barcode.Barcode('mask');
					scan.start();
					scan.onmarked = function(type, result) {
						if(result) {
							scan.close();
							var strA = result.split('t=')[1].split('&d=')
							if(strA[0] === '1') { //会员中心ID
								config.ajax({
									url: '/redemption/checkVip',
									data: {
										userId: 2 * 100000000 + strA[1] * 1
									},
									success: function(res) {
										if(res.result === 1) {
											userInfo.point = res.point
											userInfo.userName = res.userName
											userInfo.userId = 2 * 100000000 + res.userId * 1
											userInfo.header = res.header
											userInfo.openId = res.openId
											next()
										} else {
											mui.toast(res.errormsg)
											setTimeout(function() {
												//       	var wn = plus.webview.getLaunchWebview(); //传递消息返回的webview
												plus.webview.currentWebview().close();
											}, 200)
										}
									}
								})
							} else if(strA[0] === '2') {
								config.ajax({
									url: '/scanf/parseTicket.do',
									data: {
										data: strA[1]
									},
									success: function(res) {
										if(res.result === 1) {
												extra = {
													res: res,
													currentShopObj: currentShopObj
												}
												next()
										} else {
											mui.toast(res.errormsg)
											setTimeout(function() {
												//       	var wn = plus.webview.getLaunchWebview(); //传递消息返回的webview
												plus.webview.currentWebview().close();
											}, 200)
										}
									}
								})
							} else if(strA[0] === '3') {
								config.ajax({
									url:'/live/getInfo',
									data:{
										data:strA[1]
									},
									success:function(res){
										if(res.result ===1) {
											 extra = {
												currentShopObj: currentShopObj,
												res: res.userdata,
												data:strA[1],
												type:4
											}
											next(4)
										} else {
											mui.toast(res.errormsg)
											setTimeout(function() {
												//       	var wn = plus.webview.getLaunchWebview(); //传递消息返回的webview
												plus.webview.currentWebview().close();
											}, 200)
										}
									}
								})
							}
						}
					};
				}, 200)
				//处理返回事件
				plus.key.addEventListener('backbutton', function() {
					plus.webview.currentWebview().close();
				})
			}

			function receiveParams() {
				var self = plus.webview.currentWebview()
				currentShopObj = self.currentShopObj
				type = self.type
			}

			function next(nType) {
				if(nType) {type = nType}
				if(type === 1) {
					var title = '娃娃兑积分'
					var url = '../integral/recovery-goods.html'
					var id = 'recovery-goods'
					extra = {
						currentShopObj: currentShopObj,
						userInfo: userInfo
					}
				} else if(type === 2) {
					var title = '存彩票'
					var url = '../ticket/storeTicket.html'
					var id = 'storeTicket'
				} else if(type === 3) {
					var title = '兑换礼品'
					var url = '../exchange/exchange.html'
					var id = 'exchange'
					extra = {
						currentShopObj: currentShopObj,
						userInfo: userInfo
					}
				} else if(type === 4) {
					var title = '兑换礼品'
					var url = '../exchange/exchange.html'
					var id = 'exchange'
				}
				mui.openWindow({
					url: url,
					id: id,
					styles: {
						top: 0, //新页面顶部位置
						bottom: 0, //新页面底部位置         
						titleNView: {
							titleText: title,
							titleColor: "#FFFFFF",
							titleSize: "17px",
							backgroundColor: "#FF6800",
							autoBackButton: true,
							//                homeButton: true,
							buttons: [{
								float: "right",
								fontSize: "18px",
								fontSrc: "_www/fonts/iconfont.ttf", //wap2app内置字体文件
								text: "\ue602",
								onclick: function() {
									var allPage = plus.webview.all()
									var nowPage = plus.webview.getWebviewById('index')
									for(var i = 0; i < allPage.length; i++) {
										if(allPage[i].getURL() !== nowPage.getURL()) {
											plus.webview.close(allPage[i]);
										}
									}
								}
							}],
							splitLine: {
								color: "#CCCCCC",
								height: "1px"
							}
						}
					},
					extras: extra
				})
				setTimeout(function() {
					//       	var wn = plus.webview.getLaunchWebview(); //传递消息返回的webview
					plus.webview.currentWebview().close();
				}, 400)
			}
		</script>
	</body>

</html>